

package ModelLayer;
import java.util.ArrayList;

/**
 * Write a description of class DvdContainer here.
 * 
 * @author Mikkel Gunvald 
 * @version (a version number or a date)
 */
public class DvdContainer
{
    // instance variables 
    private ArrayList<Dvd> dvds;

    /**
     * Constructor for objects of class DvdContainer
     */
    public DvdContainer()
    {
        // initialise instance variables
        dvds = new ArrayList<Dvd>();
        
    }

    public void addDvd(Dvd dvd){
        dvds.add(dvd);     
    }
   
    public void createDvd(int id,String titel,String artist,int releaseYear){
        Dvd dvd = new Dvd(id,titel,artist,releaseYear); 
        dvds.add(dvd);
    }
    
    public void removeDvd(int id){
      Dvd dvd = null;
        int index = 0;
       boolean found = false;
       while(index<dvds.size() && !found){
           dvd = dvds.get(index);
            if(id == dvd.getId()){
                dvds.remove(dvd);
                found = true;
                System.out.println("Deleted " +dvd.getTitel());
            }
            index++;
            
          }
          if(found == false){
                System.out.println("Could not find DVD");
            }
    }
    
    
    public Dvd findDvd(String titel){
        Dvd tempDvd = null;
        
        for(Dvd i: dvds){
            if(titel == i.getTitel()){
                tempDvd = i;
            }
        }
        return tempDvd;
    }
    
    public void printAllDvds(){
        System.out.println("DVDs");
        int n = 1;
        for (Dvd i : dvds)
        {
            System.out.println(+ n +". " + i.getTitel());
            n++;
        }
      
    }
    
    
    public void printDvdInfo(int id){

        for (Dvd i : dvds)
        {
            if(id == i.getId())
                i.printDvdInfo();
            }
    }
    
    public int titelToId(String titel){
       int tempId = 0;
       for(Dvd i: dvds){
           if(titel== i.getTitel())
                tempId = i.getId();
        }
       return tempId;
    }
    
    
}
